<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>移动端rem适配原理</title>
 <style>
    /* html{
        font-size: 20px;
    } */
    .box-px{
        width: 300px;
        height: 100px;
        background-color: cornflowerblue;
        margin-bottom: 50px
    }
    .box-rem{
        width: 5rem;
        height: 3rem;
        background-color: darkgoldenrod;
    }
 </style>
</head>
<body>
    <div class="box-px"></div>
    <div class="box-rem"></div>
    <script>
        // 根据设备宽度计算 HTML标签的 font-size 的属性值
        function resetHTMLfontSize(){
            document.documentElement.style.fontSize=screen.width/10+'px';
        }
        resetHTMLfontSize()
        // 绑定事件
        window.onresize=resetHTMLfontSize;
    </script>
</body>
</html>